package com.salt.admin.api.feign.hystrix;

import com.salt.admin.api.feign.client.SystemFileClient;
import com.salt.admin.api.model.SystemFile;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Description
 * @Author salt
 * @Date 2022/4/14
 * @Version 1.0.1
 */
@Slf4j
@Component
public class SystemFileClientHystrix implements FallbackFactory<SystemFileClient> {

    @Override
    public SystemFileClient create(Throwable throwable) {
        String message = throwable.getMessage() == null ?
                "No available server for client: ADMIN-CENTER" :
                throwable.getMessage();
        log.info("Hystrix:{}", message);
        return new SystemFileClient() {

            @Override
            public List<SystemFile> findList(SystemFile systemFile) {
                log.info("获取系统配置文件列表异常");
                return null;
            }

            @Override
            public SystemFile find(SystemFile systemFile) {
                return null;
            }
        };
    }
}
